package fr.cephb.joperon.core.db;




import com.sleepycat.db.DatabaseException;

import fr.cephb.joperon.core.Operon;
import fr.cephb.joperon.core.db.base.BaseUTermsDB;
import fr.cephb.joperon.core.entities.UTerms;
import fr.cephb.util.Pair;

/**
 * 
 * @author lindenb
 *
 */
public class UTermsDB extends BaseUTermsDB
	{
	
	public UTermsDB(Operon operon)
		{
		super(operon);
		}

	/**
	 * finds a term-id from a query
	 * @param query the term to search
	 * @return the term-id or null if it was not found
	 */
	public Integer getTermId(String query) throws DatabaseException
		{
		UTerms term= get(query);
		return term==null?null:term.getTid();
		}
	
	
	
	public static void main(String[] args) {
			try {
				Operon op = Operon.newInstance();
				
				UTermsDB db= null;
				try
				{
				db=new UTermsDB(op);
				db.open();
				int i=0;
				UTermsDB.KeyValueIterator iter=db.listKeyValues();
				while(iter.hasNext())
					{
					Pair<String,UTerms> p=iter.next();
					System.err.println("["+p.first()+"] "+p.second());
					if(++i==500) break;
					}
				iter.close();
				System.err.println("<<<<<<");
				iter=db.listKeyValues("Rotavirus", "Rotavirus", true);
				while(iter.hasNext())
					{
					Pair<String,UTerms> p=iter.next();
					System.err.println("XXX"+p.first()+" "+p.second());
					if(++i==50000) break;
					}
				System.err.println("<<<<<");
				
				iter.close();
				}
			catch(Throwable err)
				{
				err.printStackTrace();
				}
			finally
				{
				if(db!=null) db.close();
				op.close();
				}
			} catch (Exception e) {
			e.printStackTrace();
			}
			
		}

}
